import jdk.internal.dynalink.beans.StaticClass;

import java.util.Arrays;
import java.util.Random;
import java.util.Stack;

/*
*一维数组
* 1.定义：
*  类型[] 数组名=new 类型[大小];
*  类型 数组名[] =new 类型[大小];
*  2.数组元素引用：数组名[下标]
*     下标的下限为0 上限为数组的大小-1
 */
public class Array {
    public  static void main(String[] args){
        int[] a=new  int[5];
        String b[]=new String[10];
        out(a);//调用out函数
        out(b);
        setRandom(a);
        out(a);
        //out(b);
        int f[]=new  int[20];
        fb(f);
        out(f);
        int c[]=new int[5];//定义数组
        setRandom(c);//赋随机值
        out(c);//输出c数组
        c=insert(a,30,2);//在c数组的下标为2的位置插入30
        out(c);//输入c数组
        delete(c,2);
        out(c);
        c=delete(c,4);
        out(c);

    }
    //斐波那契数列
    static void fb(int[] x) {
        x[0] = x[1] = 1;
        for (int i = 2; i < x.length; i++) {
            x[i] = x[i - 1] + x[i - 2];
        }
    }

    //插入
    static int[]  insert(int[] x,int value,int pos){
        int [] t=new int[x.length+1];
        for (int i=0;i<x.length;i++){
            t[i]=x[i];
        }
            for(int i=t.length-1;i>pos;i--){
            t[i]=t[i-1];
        }
        t[pos]=value;
        return t;
    }
    //删除
    static int[]  delete(int[] x,int pos){
        for(int i=pos;i<x.length-1;i++){
            x[i]=x[i+1];
        }
   return Arrays.copyOf(x,x.length-1);
    }


    static  void  setRandom(int[] x){
        Random r=new Random();
        for (int i=0;i<x.length;i++){
            x[i]=r.nextInt(100);
        }

    }
    static  void  out(int[] x){
        for (int e:x){
            System.out.print(e+" ");
        }
        System.out.println();
    }
    static  void  out(String[] x){
        for (int i=0;i<x.length;i++){
            System.out.print(x[i]+" ");
        }
        System.out.println();

    }
}
